/**
 * Alipay.com Inc.
 * Copyright (c) 2004-2011 All Rights Reserved.
 */
package com.alipay.supergw.common.dal.share_supergw.auto.ibatis;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import com.alipay.supergw.common.dal.share_supergw.auto.daointerface.LogonStatusDAO;
import com.alipay.supergw.common.dal.share_supergw.auto.dataobject.LogonStatusDO;
import org.springframework.dao.DataAccessException;
import java.util.List;

/**
 * An ibatis based implementation of dao interface <tt>com.alipay.supergw.common.dal.share_supergw.auto.daointerface.LogonStatusDAO</tt>.
 *
 * This file is generated by <tt>supergw-dalgen</tt>, a DAL (Data Access Layer)
 * code generation utility specially developed for <tt>supergw</tt> project.
 * 
 * PLEASE DO NOT MODIFY THIS FILE MANUALLY, or else your modification may
 * be OVERWRITTEN by someone else. To modify the file, you should go to 
 * directory <tt>(project-home)/dalgen</tt>, and 
 * find the corresponding configuration file (<tt>tables/sgw_logon_status.xml</tt>). 
 * Modify the configuration file according to your needs, then run <tt>supergw-dalgen</tt> 
 * to generate this file.
 */
public class IbatisLogonStatusDAO extends SqlMapClientDaoSupport implements LogonStatusDAO {

    /**
     *  Update DB table <tt>sgw_logon_status</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>update sgw_logon_status set session_id=?, status=?, gmt_modified=sysdate where (channel_system_id = ?)</tt>
     *
     *	@param logonStatus
     *	@return int
     *	@throws DataAccessException
     */
    public int update(LogonStatusDO logonStatus) throws DataAccessException {
        if (logonStatus == null) {
            throw new IllegalArgumentException("Can't update by a null data object.");
        }

        return getSqlMapClientTemplate().update("MS-LOGON-STATUS-UPDATE", logonStatus);
    }

    /**
     *  Update DB table <tt>sgw_logon_status</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>update sgw_logon_status set status='WAIT', gmt_modified=sysdate where ((channel_system_id = ?) AND (status != 'WAIT'))</tt>
     *
     *	@param logonStatus
     *	@return int
     *	@throws DataAccessException
     */
    public int lock(LogonStatusDO logonStatus) throws DataAccessException {
        if (logonStatus == null) {
            throw new IllegalArgumentException("Can't update by a null data object.");
        }

        return getSqlMapClientTemplate().update("MS-LOGON-STATUS-LOCK", logonStatus);
    }

    /**
     *  Query DB table <tt>sgw_logon_status</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select channel_system_id, session_id, status, expire_time, gmt_create, gmt_modified from sgw_logon_status where (channel_system_id = ?)</tt>
     *
     *	@param channelSystemId
     *	@return LogonStatusDO
     *	@throws DataAccessException
     */
    public LogonStatusDO loadByChannelSystemId(String channelSystemId) throws DataAccessException {

        return (LogonStatusDO) getSqlMapClientTemplate().queryForObject(
            "MS-LOGON-STATUS-LOAD-BY-CHANNEL-SYSTEM-ID", channelSystemId);

    }

    /**
     *  Query DB table <tt>sgw_logon_status</tt> for records.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>select channel_system_id, session_id, status, expire_time, gmt_create, gmt_modified from sgw_logon_status</tt>
     *
     *	@return List<LogonStatusDO>
     *	@throws DataAccessException
     */
    @SuppressWarnings("unchecked")
    public List<LogonStatusDO> loadAll() throws DataAccessException {

        return getSqlMapClientTemplate().queryForList("MS-LOGON-STATUS-LOAD-ALL", null);

    }

    /**
     *  Update DB table <tt>sgw_logon_status</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>update sgw_logon_status set status=?, expire_time=?, gmt_modified=sysdate where (channel_system_id = ?)</tt>
     *
     *	@param logonStatus
     *	@return int
     *	@throws DataAccessException
     */
    public int updateIncludeExpireTime(LogonStatusDO logonStatus) throws DataAccessException {
        if (logonStatus == null) {
            throw new IllegalArgumentException("Can't update by a null data object.");
        }

        return getSqlMapClientTemplate().update("MS-LOGON-STATUS-UPDATE-INCLUDE-EXPIRE-TIME",
            logonStatus);
    }

    /**
     *  Insert one <tt>LogonStatusDO</tt> object to DB table <tt>sgw_logon_status</tt>, return primary key
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>insert into sgw_logon_status(channel_system_id,session_id,status,expire_time,gmt_create,gmt_modified) values (?, ?, ?, ?, sysdate, sysdate)</tt>
     *
     *	@param logonStatus
     *	@return String
     *	@throws DataAccessException
     */
    public String insert(LogonStatusDO logonStatus) throws DataAccessException {
        if (logonStatus == null) {
            throw new IllegalArgumentException("Can't insert a null data object into db.");
        }

        getSqlMapClientTemplate().insert("MS-LOGON-STATUS-INSERT", logonStatus);

        return logonStatus.getChannelSystemId();
    }

    /**
     *  Delete records from DB table <tt>sgw_logon_status</tt>.
     *
     *  <p>
     *  Description for this operation is<br>
     *  <tt></tt>
     *  <p>
     *  The sql statement for this operation is <br>
     *  <tt>delete from sgw_logon_status where (channel_system_id = ?)</tt>
     *
     *	@param channelSystemId
     *	@return int
     *	@throws DataAccessException
     */
    public int delete(String channelSystemId) throws DataAccessException {

        return getSqlMapClientTemplate().delete("MS-LOGON-STATUS-DELETE", channelSystemId);
    }

}